﻿using AdverseEventReportSystem.BLL.NursingFormSystem;
using AdverseEventReportSystem.Core;
using AdverseEventReportSystem.Utils;
using NursingFormSystem.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AdverseEventReportSystem.Web.Areas.NursingForm.Controllers
{
    [LoginAttribute(IsNeed = false)]
    public class ParturitionController : BaseController
    {
        // GET: NursingForm/Parturition
        public ActionResult Index(string patientId, int visitId)
        {
            ViewBag.PatientId = patientId;
            ViewBag.VisitId = visitId;
            return View();
        }

        /// <summary>
        /// 获取分娩记录单
        /// </summary>
        /// <returns></returns>
        public ActionResult GetParturition()
        {
            OperateResult resultInfo = new OperateResult();
            string patientId = WebUtils.GetSafeString("patientId");
            if (patientId.IndexOf('_') > -1)
            {
                patientId = patientId.Split('_')[0];
            }
            int visitId = WebUtils.GetInt("visitId");
            NursingFormSoapClient service = new NursingFormSoapClient();
            ActionOperateResultOfString serviceResult = service.GetNursingFormRecordByDate(patientId, visitId, (int)FormType.Parturitions, new DateTime(2000, 1, 1), new DateTime(2100, 1, 1));
            List<Parturition> list = new List<Parturition>();
            if (serviceResult.Code == 1)
            {
                List<NursingFormRecord> recordList = JsonHelper.DeserializeObject<List<NursingFormRecord>>(serviceResult.D);
                foreach (var item in recordList)
                {
                    list.Add(XmlHelper.XmlDeserialize<Parturition>(item.NursingFormData));
                }
                resultInfo.Body = list[0];
            }
            else
            {
                resultInfo.Result = serviceResult.Code;
                resultInfo.Body = serviceResult.M;
            }

            return JsonDate(resultInfo);
        }
    }
}